package as2.model;

import java.util.List;

import as2.model.pojo.Order;
import as2.model.pojo.OrderStatus;
import as2.model.pojo.User;

public class ExampleUsage {

	public static void main(String[] args) {
		// user authenticate
		User user = UserService.getUser("user1", "user1pw");
		if (user == null) {
			// user name not exist or pw wrong
		}
		System.out.println(user);

		// user adding item to shopping cart
		Order order = new Order(user);
		order.addItems("myItemId_1", 10);
		order.addItems("myItemId_2", 20);
		order.addItems("myItemId_3", 30);
		order.removeItems("myItemId_1", 5);
		order.removeItems("myItemId_2");

		// user adding address at checkout
		order.setAddressCity("myCity");

		// system compute shipping cost and total cost
		order.setShippingCost(100);

		// order finalized and save
		OrderService.save(order);
		// Renew the user to reflect new orders
		UserService.refresh(user);
		System.out.println(user.getOrders());

		// admin can change order status
		List<Order> allOrders = OrderService.getAllOrders();
		order = allOrders.get(0);
		order.setStatus(OrderStatus.SHIPPED);
		OrderService.save(order);

		System.exit(0);
	}
}
